package com.doudou.commons.validate;


import lombok.extern.slf4j.Slf4j;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Classname Phone
 * @Description 手机号验证
 * @Date 2019/9/10 10:40
 * @Created lihd
 */
@Slf4j
public class PhoneHandler implements ConstraintValidator<Phone,Object> {
    @Override
    public boolean isValid(Object obj, ConstraintValidatorContext constraintValidatorContext) {
        if(null == obj){
            return false;
        }
        String regexp = "(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[3-8]{1})|(18[0-9]{1})|(19[0-9]{1})|(14[5-7]{1}))+\\d{8})$";
        return ((String) obj).matches(regexp);
    }
}
